package com.dq.controller.api.org;

import com.dq.exception.customException.AdminException;
import com.dq.vo.Vo;
import com.dq.domain.org.Org;
import com.dq.domain.org.OrgHonorWall;
import com.dq.domain.sys.user.user.base.SysUser;
import com.dq.service.AllService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @Author luchangtong
 * @Date 2019/11/22 15:23
 */
@Api(description = "门店荣誉墙")
@RestController
@RequestMapping("/api/orgHonorWall")
public class OrgHonorWallController extends AllService {

    @ApiOperation("查看门店荣誉墙")
    @GetMapping("getOrgHonorWall")
    public Vo getOrgHonorWall() throws AdminException{
        HashMap<String,Object> map = new HashMap<>();
        SysUser user = shiroService.getUser();
        Org org = (Org) user.getSection();
        if(org == null){
            throw new AdminException("请绑定门店");
        }
        List<OrgHonorWall> orgHonorWalls = orgHonorWallRepository.findBySysDeptAndDeletedFalse((Org) user.getSection());
        List<OrgHonorWall.OrgHonorWallVo> honorWallVoList = new ArrayList<>();
        orgHonorWalls.forEach(orgHonorWall -> {
            honorWallVoList.add(orgHonorWall.toOrgHonorWallVo());
        });
        map.put("orgImg",org.getOrgImg());
        map.put("orgName",org.getSimpleName());
        map.put("orgAddress",org.getAddress());
        map.put("orgPhone",org.getFixedPhone());
        map.put("honorWallVoList",honorWallVoList);
        return new Vo(map);
    }
}
